package com.ymm.lulutong.repo;

import com.ymm.lulutong.request.CargoDefinePriceWebRequest;
import com.ymm.lulutong.translator.RequestTranslator;
import com.ymm.system.api.dto.CargoPriceRequest;
import com.ymm.system.api.facade.SystemDefinePriceService;
import com.ymm.system.api.utils.Result;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service;

@Service
public class SystemDefinePriceServiceRepo {
    @Reference(version = "server")
//    @Reference
    SystemDefinePriceService systemDefinePriceService;

    public com.ymm.lulutong.utils.Result<Integer> definePrice(CargoDefinePriceWebRequest cargoDefinePriceWebRequest) {
        CargoPriceRequest cargoPriceRequest = RequestTranslator.CargoDefinePriceWebRequest2CargoPriceRequest(cargoDefinePriceWebRequest);
        return systemResult2ShipperResult(systemDefinePriceService.definePrice(cargoPriceRequest));
    }

    private com.ymm.lulutong.utils.Result systemResult2ShipperResult(com.ymm.system.api.utils.Result result) {
        if (result.isSuccess()) {
            return com.ymm.lulutong.utils.Result.success(result.getData());
        }
        return com.ymm.lulutong.utils.Result.fail(result.getData(), result.getCode(), result.getMessage());
    }
}
